package com.timguan.render.dataprocessor.processor;

import org.apache.commons.lang.StringUtils;

/**
 * Created by guankaiqiang on 2014/12/16.
 */
public class URLHelper {
    private static final String HTML_SUFFIX = ".html";

    public static String getItemLink(String itemId, int appid) {
        if (StringUtils.isBlank(itemId)) {
            return "";
        } else {
            if (appid == Constants.B2C_PC_APPID) {
                return Constants.ITEM_URL_PREFIX + itemId + HTML_SUFFIX;
            } else {
                return Constants.H5_ITEM_URL_PREFIX + itemId + HTML_SUFFIX;
            }
        }
    }

    public static String getItemLink4PC(String itemId) {
        return getItemLink(itemId, Constants.B2C_PC_APPID);
    }

    public static String getItemLink4H5(String itemId) {
        return getItemLink(itemId, Constants.B2C_H5_APPID);
    }

    public static String getActivityLink4PC(String activityId) {
        if (org.apache.commons.lang.StringUtils.isBlank(activityId)) {
            return "";
        }
        return Constants.ACTIVITY_URL_PREFIX + activityId + HTML_SUFFIX;
    }

    public static String getActivityLink4H5(String activityId) {
        if (org.apache.commons.lang.StringUtils.isBlank(activityId)) {
            return "";
        }
        return Constants.H5_ACTIVITY_URL_PREFIX + activityId + HTML_SUFFIX;
    }

    public static String getUrl(int targetActivityType, String targeUri, int targetActivityId) {
        String redirectURL = null;
        if (targetActivityType == Constants.PC_PAGE_TYPE) {
            if (targetActivityId > 0) {
                redirectURL = Constants.ACTIVITY_URL_PREFIX + targetActivityId + ".html";
            } else {
                redirectURL = Constants.BASE_URL + "/" + targeUri + ".html";
            }
        } else {
            if (targetActivityId > 0) {
                redirectURL = Constants.H5_ACTIVITY_URL_PREFIX + targetActivityId + ".html";
            } else {
                redirectURL = Constants.H5_BASE_URL + "/" + targeUri + ".html";
            }
        }
        return redirectURL;
    }
}
